local sk__tianqi = fk.CreateSkill {

  name = "sk__tianqi",

  tags = {},

}



sk__tianqi:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic,trick",
  prompt = "#sk__tianqi",
  expand_pile = function(self, player)
    return { Fk:currentRoom().draw_pile[1] }
  end,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("bt")
    local names = player.getViewAsCardNames(player, "sk__tianqi", all_names)
    return UI.CardNameBox { choices = names, all_choices = all_names }
  end,
  card_filter = function(self, player, to_select, selected, selected_targets)
    return #selected == 0 and Fk:currentRoom().draw_pile[1] == to_select
  end,
  view_as = function(self, player, cards)
    if not self.interaction or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(cards)
    card.skillName = sk__tianqi.name
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    if Fk.currentResponsePattern == nil and player.phase == Player.Play then
      room:setPlayerMark(player, "sk__tianqi-phase", 1)
    end
    if room.draw_pile == 0 then
      room:shuffleDrawPile()
      if room.draw_pile == 0 then
        room:gameOver("")
      end
    end
    local id = use.card.subcards[1]
    if Fk:getCardById(id) and use.card and Fk:getCardById(id).type ~= use.card.type and not player.dead then
      room:loseHp(player, 1, sk__tianqi.name)
    end
  end,
  enabled_at_play = function(self, player)
    return (player.phase == Player.Play and player:usedSkillTimes(sk__tianqi.name, Player.HistoryPhase) == 0) or
        (player.phase ~= Player.Play and player.dying == false)
  end,
  enabled_at_response = function(self, player, response)
    return ((player.phase == Player.Play and player:usedSkillTimes(sk__tianqi.name, Player.HistoryPhase) == 0) or
          (player.phase ~= Player.Play and player.dying == false)) and Fk.currentResponsePattern and
        Exppattern:Parse(Fk.currentResponsePattern):matchExp(self.pattern)
  end,
})

return sk__tianqi
